package net.ojbk.sso.center.service;

import net.ojbk.sso.center.beans.po.User;
import net.ojbk.sso.center.beans.pojo.TokenSystem;
import net.ojbk.sso.center.beans.vo.VO_LoggedWebsites;
import net.ojbk.sso.center.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: twobox
 * Date: 2019/3/24
 * Time: 11:36
 * Description: No Description
 */
@Service
public class LoginService {
    @Autowired
    private TokenSystem tokenSystem;

    @Autowired
    private UserDao userDao;

    public User login(String uid, String pwd, HttpSession httpSession) {
        User user = new User();
        user.setUid(uid);
        user = userDao.selectOneById(user);
        if (user == null || !user.getPasswd().equals(pwd))
            return null;
        tokenSystem.fastLogin(httpSession);
        return user;
    }

    public String getUid (HttpSession session) throws Exception{
        User user = (User) session.getAttribute("user");
        return user.getUid();
    }

}
